function loadControlPoint(obj,node)
%load control points from XML file

% This file is part of CISNE.
%
%     CISNE is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     any later version.
%
%     CISNE is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
%
%     You should have received a copy of the GNU General Public License
%     along with CISNE.  If not, see <http://www.gnu.org/licenses/>.

% Copyright 2013. Jose Maria Garcia-Valdecasas Bernal


handles=guidata(obj.m_figure);
%node is the CPOINTS node. ChildNodes are the Points
childNodes=node.getChildNodes();
for j=0:childNodes.getLength()-1
    %get one point
    child=childNodes.item(j);
    %retrieve name of the point
    name=char(child.getAttribute('Name'));
    %items are the properties of the grid
    items=child.getChildNodes();
    %data will be the grid data stored in the gridlist
    data=cell(items.getLength,4);
    for k=0:items.getLength()-1
        %store the info of the item in the data cell
        elem=char(items.item(k).getNodeName());
        elem=regexprep(elem,'_',' ');
        text=char(items.item(k).getAttribute('txt'));
        kind=char(items.item(k).getAttribute('kind'));
        value=char(items.item(k).getTextContent());
        value=txt2data(value,kind);
        data(k+1,:)={elem,text,kind,value};        
    end
    
    model=get(obj.m_tree,'model');
    root=obj.m_tree.Root();
    for l=0:get(root,'ChildCount')-1
        branch=root.getChildAt(l);
        kind=branch.getValue();
        kind=char(kind(2));
        if (strcmp(kind,'CPOINTS'))
            %we add a new child in this node
            parent=branch;
            type=['point_' regexprep(name,'\s+','_')];
            branch=uitreenode('v0',{'unselected',type},name,[], true);
            model.insertNodeInto(branch,parent,parent.getChildCount());
            obj.m_grids.(type)=data;
            break;
        end
    end
    %draw point in the DisplayWidget
    handles.DisplayWidget.addCPoint(type);
    obj.updateDisplay(branch);
    
end

end

function data=txt2data(text,kind)

switch kind
    case 'num'
        data=str2double(text);
    case 'bool'
        if strcmp(text,'false')
            data=false;
        else
            data=true;
        end
    otherwise
        if strcmp(kind,'file')||strcmp(kind,'style') 
            data=text;
        else
            data=str2double(text);
        end
end
end
